package main

func multiply(num1 string, num2 string) string {
	if num1[0] == '0' || num2[0] == '0' {
		return "0"
	}

	if len(num1) > len(num2) {
		temp := num1
		num1 = num2
		num2 = temp
	}

	//sums := make([]string, 0)
	result := ""
	for i := len(num1) - 1; i >= 0; i-- {
		jin := byte(0)
		sum := ""
		for j := len(num2) - 1; j >= 0; j-- {
			b := (num2[j] - '0') * (num1[i] - '0')
			b += jin
			jin = b / 10
			sum = string(b%10+'0') + sum
		}

		if jin != 0 {
			sum = string(jin+'0') + sum
		}

		for k := len(num1) - 1; k > i; k-- {
			sum += "0"
		}

		if i == len(num1)-1 {
			result = sum
			continue
		}

		temp := ""
		jin = 0

		for k := len(sum) - 1; len(result)-1-(len(sum)-1-k) >= 0 && k >= 0; k-- {
			t := sum[k] - '0' + result[len(result)-1-(len(sum)-1-k)] - '0'
			t += jin
			jin = t / 10
			temp = string(t%10+'0') + temp
		}

		for k := len(sum) - len(result) - 1; k >= 0; k-- {
			temp = string((sum[k]-'0'+jin)%10+'0') + temp
			jin = (sum[k] + jin - '0') / 10
		}

		if jin > 0 {
			temp = string(jin+'0') + temp
		}

		result = temp
	}

	return result
}
